#pragma once

#include <iostream>
#include <cstring>
#include <functional>
#include "InetAddr.hpp"

// 保证每个fd都各有一套缓冲区

class Reactor;
class Channel;

using handler_t = std::function<void(std::shared_ptr<Channel> channel)>;

class Connection
{
public:
    Connection() : _events(0), _owner(nullptr)
    {
    }
    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Excepter() = 0;
    virtual int GetFd() = 0;
    std::string Inbuffer(std::string *out)
    {
        return std::string();
    }
    void AppendOutBuffer(std::string &out) 
    {
    }

    void RegisterHandler(handler_t handler)
    {
        _handler = handler;
    }
    void SetEvent(uint32_t event)
    {
        _events = event;
    }
    uint32_t GetEvent()
    {
        return _events;
    }
    void SetOwner(Reactor *owner)
    {
        _owner = owner;
    }
    Reactor *GetOwner()
    {
        return _owner;
    }
    ~Connection()
    {
    }

private:
    // 回指指针
    Reactor *_owner;

    // 关心事件
    uint32_t _events;

public:
    handler_t _handler;
};